/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.web.servlet;
import java.io.IOException;
import com.web.entity.Test;
import com.web.service.Testdaoimpl;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 请求获取题目
 *
 * @author liqianru
 */
@WebServlet("/getTest")
public class Test_servlet extends HttpServlet {

    Testdaoimpl testdao = new Testdaoimpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      
        //执行业务逻辑
        
        List<Test> list_all=testdao.getAll();
         HttpSession session=req.getSession();
         String action =req.getParameter("action");
        //生成相应
        if(action.equals("get")){
        if(list_all.isEmpty()){
        req.setAttribute("is_null", true);}
        else{
            req.setAttribute("is_null", false);
        }
        session.setAttribute("allTest", list_all);
        req.getRequestDispatcher("question_bank.jsp").forward(req, resp);}
        if(action.equals("search_Test")){
            String keyword=req.getParameter("keyword");
            list_all=testdao.getBykeyword(keyword);
            session.setAttribute("allTest", list_all);
            req.getRequestDispatcher("question_bank.jsp").forward(req, resp);
        }

    }

}
